package io.littlevv.demo.spi;

import java.util.Iterator;
import java.util.ServiceLoader;

/**
 * PackageName: io.littlevv.demo.spi
 * Author:
 * Date: 2021/1/27
 * Description:
 */
public class FruitSpiFactory {
    public static void getFruitSpi() {
        ServiceLoader<FruitSpiInterface> serviceLoader = ServiceLoader.load(FruitSpiInterface.class);
        Iterator<FruitSpiInterface> fruits = serviceLoader.iterator();
        while (fruits.hasNext()) {
            System.out.println(fruits.next().getCurrentFruit());
        }
    }

    public static void main(String[] args) {
        while (true) {
            FruitSpiFactory.getFruitSpi();
            try {
                Thread.sleep(1000L);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("*******************");
        }
    }
}
